/*
 * sWarcraftMessages.h
 *
 *  Created on: 08.11.2010
 *      Author: 123
 */

#ifndef WARCRAFTMESSAGES_H_
#define WARCRAFTMESSAGES_H_
//#include "lua.h"
extern "C" {

#include    <lauxlib.h>
#include    <lualib.h>
#include "pgeFont.h"
#include<time.h>

}
#include <stdio.h>
#include "stdlib.h"
#include "string.h"
#include <oslib/oslib.h>
extern pgeFont *nash;

class WarcraftMessages {
	int i;
	int ma;
	int messalpha[5];
	char * messages[5];

public:
	friend int LuaPrint(lua_State*);
	friend int LuaShowMessage(lua_State*);
	WarcraftMessages() {

		for (i = 0; i < 5; i++) {
			messages[i] = (char*) malloc(100);
		}
	}
	void showmessage(char * str) {
		i = 0;
		while (i <= 4 && messalpha[i] > 0) {
			i = i + 1;
		}

		if (i == 5) {

			for (i = 0; i <= 3; i++) {
				memcpy(messages[i], messages[i + 1], 50);
				messalpha[i] = messalpha[i + 1];
			}
			i = 4;
		}

		int length = strlen(str);
		memcpy(messages[i], str, length + 20);
		messalpha[i] = 500;
	}

	void AlphaMinus() {
		for (i = 0; i < 4; i++) {
			if (messalpha[i] > 0)
				messalpha[i] = messalpha[i] - 1;
		}
	}

	void Print() {
		AlphaMinus();
		pgeFontActivate(nash);
		for (i = 0; i <= 4; i++) {
			if (messalpha[i] > 255)
				ma = 255;
			else
				ma = messalpha[i];
			if (messages[i] != NULL) {
				pgeFontPrintf(nash, 12, 50 + i * 16, RGBA(0,255,255,ma), "%s",
						messages[i]);
			}
		}
	}

};
extern WarcraftMessages Message;
/*int LuaPrint(lua_State* l){
 Print();
 }*/

#endif /* SWARCRAFTMESSAGES_H_ */
